home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / printing / sqprint.c < prev    next >
Internet Message Format  |  1996-11-17  |  6KB

  1. From vax@sylvester.cc.utexas.edu Tue Oct  5 22:24:17 EDT 1993
  2. Article: 2322 of comp.os.linux.misc
  3. Path: samba.oit.unc.edu!concert!news-feed-2.peachnet.edu!darwin.sura.net!howland.reston.ans.net!math.ohio-state.edu!cs.utexas.edu!geraldo.cc.utexas.edu!sylvester.cc.utexas.edu!not-for-mail
  4. From: vax@sylvester.cc.utexas.edu (Vax)
  5. Newsgroups: comp.os.386bsd.misc,comp.os.linux.misc,comp.lang.perl
  6. Subject: sqprint, a multi-page filter for HP Laserjets
  7. Date: 5 Oct 1993 19:48:47 -0500
  8. Organization: The University of Texas - Austin
  9. Lines: 228
  10. Message-ID: <28t4lf$1aa@sylvester.cc.utexas.edu>
  11. NNTP-Posting-Host: sylvester.cc.utexas.edu
  12. Keywords: PERL PCL LJ
  13. Xref: samba.oit.unc.edu comp.os.386bsd.misc:1232 comp.os.linux.misc:2322 comp.lang.perl:19177
  14.  
  15. The following PERL script was written to print multiple pages in landscape
  16. mode on a Hewlett-Packard Laserjet Series printer (PCL-lang only).
  17. I conducted a search for other programs which would do this, but the search
  18. was fruitless.  I hope the general community finds this program useful.
  19.  
  20. To use this program, you must install it in your printcap file.  I put mine
  21. in the "cf" entry, for example, in my BSD-based system:
  22.  
  23. lp|local line printer:\
  24.     :lp=/dev/lpa0:sd=/var/spool/lpd:lf=/var/log/lpd-errs:sh:\
  25.     :if=/usr/foreign/bin/if_ljet3:\
  26.     :cf=/usr/foreign/bin/sqprint:
  27.  
  28. The cf entry stands for "cif filter", or something like that.  Since I don't
  29. have cif on my machine, I used the empty printcap slot for my filter.
  30. However, if you install sqprint as a filter on your machine, be warned that
  31. users who attempt to print cif files, or whatever filter you used, will have
  32. quite a surprise in store for them.
  33.  
  34. To print on my system, I use:
  35.     lpr -c inputfilename
  36.  
  37. The "-c" tells lpd to print the file using the cif output filter.
  38.  
  39. Unfortunately, very few useful arguments (such as input filename, etc) are
  40. passed to any filters except "if" or "of", both of which you will probably
  41. not want to override.  If you do override the "if" or "of" filters, you will
  42. have to change the print_footer routine at the end of the file.
  43.  
  44. There is no guarantee of support from me, although I will probably continue
  45. to add features as I find them useful.  I never intend to make a MS-DOS port.
  46.  
  47. I will not answer any mail regarding "how to install this program" or
  48. "the program won't work with my HP calculator, what is wrong?".  If you have
  49. problems, you will have to resolve them yourself.
  50.  
  51. Check you printcap and lpr manpages for more info.
  52.  
  53. Mail kudos, remarks, subpoenas to vax@ccwf.cc.utexas.edu.
  54.  
  55. ----------If you cut here you will damage your monitor------8<-----------------
  56. #!/usr/bin/perl
  57. # sqprint v1.0
  58. # Written by vax@ccwf.cc.utexas.edu (VaX#n8) October 4th, 1993
  59. # This program may not be used in any commercial product without written
  60. # permission of the author.
  61. # This program is freely redistributable (with the exception noted above)
  62. # as long as this header remains with the file.
  63.  
  64. $line=-1;
  65. $col=-1;
  66. while (<STDIN>)
  67. {
  68.     chop;
  69.     $temp = $_;
  70.     while (($l = length($temp)) > 0)
  71.     {
  72.         $_ = substr($temp,0,($l < 80) ? $l : 80);
  73.         $temp = substr($temp,length($_));
  74.         $line = ($line + 1) % 65;
  75.         if ($line == 0)
  76.         {
  77.             if ($col == 1)
  78.             {
  79.                 # send form feed (FF)
  80.                 print "\x0C";
  81.             }
  82.             $col = ($col + 1) % 2;
  83.             if ($col == 0)
  84.             {
  85.                 &setup_page;
  86.             }
  87.             else
  88.             {
  89.                 print "\x1B&k7.2029H";
  90.                 print "\x1B&a91lhV";
  91.                 print "\n";
  92.             }
  93.             &setup_font_stuff;
  94.             &setup_column;
  95.         }
  96.         print ;
  97.         print "\n";
  98.     }
  99. }
  100.  
  101. # send form feed (FF)
  102. print "\x0C";
  103.  
  104. # reset printer
  105. print "\x1BE";
  106.  
  107.  
  108. sub setup_font_stuff
  109. {
  110.     
  111.     # set font type to PC8
  112.     print "\x1B(10U";
  113.     
  114.     # set default [non]proportional font (?)
  115.     # 16.6 CPI pitch
  116.     # 8.5 point vertical
  117.     # set default upright/italic
  118.     # set default stroke weight
  119.     # set default typeface
  120.     print "\x1B(sp16.6h8.5vsbT";
  121. }
  122.  
  123. sub draw_box
  124. {
  125.     # horizonal move to 155 decipoints
  126.     # vertical move to 452 decipoints
  127.     print "\x1B&a155h452V";
  128.     
  129.     # create a graphic element 7325 horizontal decipoints
  130.     # create a graphic element 1 vertical decipoint
  131.     # draw
  132.     print "\x1B*c7325h1vP";
  133.     
  134.     # horizontal move to 155 decipoints
  135.     # vertical move to 5652 decipoints
  136.     print "\x1B&a155h5652V";
  137.     
  138.     # same as two above
  139.     print "\x1B*c7325h1vP";
  140.     
  141.     # move to (155,452)
  142.     print "\x1B&a155h452V";
  143.     
  144.     # make a vertical line 5200 decipoints high, 1 wide 
  145.     print "\x1B*c1h5200vP";
  146.     
  147.     # move to (3830,452)
  148.     print "\x1B&a3830h452V";
  149.     
  150.     # same as two above
  151.     print "\x1B*c1h5200vP";
  152.     
  153.     # move to (7480,452)
  154.     print "\x1B&a7480h452V";
  155.     
  156.     # make another line 1 wide, 5200 high
  157.     print "\x1B*c1h5200vP";
  158.     
  159.     # move to (7524,5352)
  160.     print "\x1B&a7524h5352V";
  161. }
  162.  
  163. sub setup_page
  164. {
  165.     # reset printer
  166.     print "\x1BE";
  167.     
  168.     # print in landscape mode
  169.     print "\x1B&l1O";
  170.  
  171.     &setup_font_stuff;
  172.     
  173.     # set column width (HMI) to 7.2/120ths of an inch
  174.     print "\x1B&k7.2H";
  175.         
  176.     # set VMI to 5.2/42ths of an inch
  177.     # set default perforation skip
  178.     print "\x1B&l5.2cL";
  179.     
  180.     # set default number of lines in top margin
  181.     print "\x1B&lE";
  182.         
  183.     # set default left margin
  184.     print "\x1B&aL";
  185.     
  186.     &draw_box;
  187.  
  188.     &setup_font_stuff;
  189.     
  190.     # set HMI to 7.2029/120ths of an inch
  191.     print "\x1B&k7.2029H";
  192.     
  193.     # set VMI to 15.2/42ths of an inch
  194.     # set default perforation skip
  195.     print "\x1B&l5.2cL";
  196.     
  197.     # set line termination to cr->cr; lf->cr+lf; ff->cr+ff
  198.     print "\x1B&k2G";
  199.  
  200.     &print_footer;
  201.  
  202.     # horizontal move -5 decipoints,
  203.     # vertical move +3 decipoints
  204.     print "\x1B&a-5h+3V";
  205.     
  206.     # Set top margin 7 lines
  207.     print "\x1B&l7E";
  208.     
  209.     print "\x1B&a6lhV";
  210.     print "\n";
  211.     
  212. }
  213.  
  214. sub setup_column
  215. {
  216.     # set column width (HMI) to 7.2/120ths of an inch
  217.     print "\x1B&k7.2H";
  218.     
  219.     # set VMI to 05.200/42ths of an inch
  220.     print "\x1B&l05.200C";
  221. }
  222.  
  223. sub print_footer
  224. {
  225.     # args are of form  -xwidth -ylength -n login -h hostname acct-file
  226.  
  227.     # move to (155,5652) decipoints
  228.     print "\x1B&a155h5652V";
  229.  
  230.     print "\n";
  231.  
  232.     # 172 or more spaces for footer
  233.     print "    login: $ARGV[3]\thostname: $ARGV[5]\n";
  234.     
  235.     print "\x1B&a+5h-3V";
  236.     
  237.     # an emply line that's left open for later stuff
  238.     print "\n";
  239. }
  240. -- 
  241. Protect our endangered bandwidth - reply by email.  NO BIG SIGS!
  242. VaX#n8 vax@ccwf.cc.utexas.edu - Don't blame me if the finger daemon is down
  243.  
  244.  
  245.